﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppGene.DataModel
{
    /// <summary>
    /// The class provide a describe for a column field in table class.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class LogicalColumnAttribute
        : Attribute
    {
        /// <summary>
        /// Create a logical column attribute instance.
        /// </summary>
        public LogicalColumnAttribute()
        { }

        /// <summary>
        /// Gets or Sets if allow null value to the column.
        /// </summary>
        public bool AllowNull { get; set; }

        /// <summary>
        /// The data type of the column.
        /// </summary>
        public DbType DataType { get; set; }

        /// <summary>
        /// The default value of the column.
        /// </summary>
        public object DefaultValue { get; set; }

        /// <summary>
        /// The description of the column.
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// The identity increment of the column.
        /// </summary>
        public int IdentityIncrement { get; set; }

        /// <summary>
        /// The identity seed of the column
        /// </summary>
        public int IdentitySeed { get; set; }

        private bool isIdentity;
        /// <summary>
        /// Is Identity
        /// </summary>
        public bool IsIdentity
        {
            get
            {
                return isIdentity;
            }
            set
            {
                isIdentity = value;
                if (isIdentity)
                {
                    this.IdentitySeed = 1;
                    this.IdentityIncrement = 1;
                }
                else
                {
                    this.IdentitySeed = 0;
                    this.IdentityIncrement = 0;
                }
            }
        }

        /// <summary>
        /// The label of the column.
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// The length of the column.
        /// </summary>
        public int Length { get; set; }

        /// <summary>
        /// The name of the column.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// The native data type.
        /// </summary>
        public string NativeDataType { get; set; }

        /// <summary>
        /// The column options. Any options will be added at the end of column definition.
        /// </summary>
        public string Options { get; set; }
        
        /// <summary>
        /// The order of the column in the table.
        /// </summary>
        public int Order { get; set; }

        /// <summary>
        /// The precision of the column.
        /// </summary>
        public int Precision { get; set; }

        /// <summary>
        /// The scale of the column.
        /// </summary>
        public int Scale { get; set; }
    }
}
